package com.banzhi.shop.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.banzhi.shop.R;
import com.banzhi.shop.entity.shoppingcart.Cartdata;
import com.banzhi.shop.utils.ASUtils;
import com.banzhi.shop.utils.NumberUtils;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by HT on 2017/5/22.
 */

public class OrderAffirmCartAdapter extends BaseAdapter<Cartdata> {
    public OrderAffirmCartAdapter(Context context, List<Cartdata> data) {
        super(context, data);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Cartdata data = getData().get(position);
        viewHolder holder = null;
        if (convertView == null) {
            holder = new viewHolder();
            convertView = getInflater().inflate(R.layout.item_cart_queren_order, null);
            holder.ivimage = (ImageView) convertView.findViewById(R.id.iv_image);
            holder.tvtitle = (TextView) convertView.findViewById(R.id.tv_title);
            holder.tvguige = (TextView) convertView.findViewById(R.id.tv_guige);
            holder.tvnumber = (TextView) convertView.findViewById(R.id.tv_number);
            holder.tvprice = (TextView) convertView.findViewById(R.id.tv_price);
            convertView.setTag(holder);
        }
        holder = (viewHolder) convertView.getTag();
        if (ASUtils.isCanUse(data.getThumb())) {
            Picasso.with(getContext()).load(data.getThumb()).placeholder(R.mipmap.zhanweitu2).into(holder.ivimage);
        } else {
            holder.ivimage.setImageResource(R.mipmap.moren);
        }
        holder.tvtitle.setText(data.getTitle());
        if (data.getTitle1() != null && !"".equals(data.getTitle1())) {
            holder.tvguige.setText(data.getTitle1());
        }
        holder.tvnumber.setText(data.getTotal());
        if (ASUtils.isCanUse(data.getMarketprice())) {
            holder.tvprice.setText(NumberUtils.DecimalFormat(data.getMarketprice()));
        }

        return convertView;
    }

    class viewHolder {
        ImageView ivimage;
        TextView tvtitle;
        TextView tvguige;
        TextView tvnumber;
        TextView tvprice;
    }
}
